﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;


[CustomPropertyDrawer(typeof(Person))]
public class PersonPropertiesDrawer : PropertyDrawer
{

    Rect top, middleRight, middeLeft, bottom;
    SerializedProperty personName, sex, age, description;
    //绘制属性
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {

        //顶部
        top = new Rect(position.x,
            position.y,
            position.width,
            position.height );
        //左中部
        middeLeft = new Rect(position.x,
            position.y + (position.height * 2),
            position.width / 2.0f,
            position.height );
        //右中部
        middleRight = new Rect(position.x + position.width / 2.0f,
            position.y + (position.height * 2),
            position.width / 2.0f,
            position.height );
        //底部
        bottom = new Rect(position.x,
            position.y + position.height * 3,
            position.width,
            position.height);
        //获取对应的属性
        personName = property.FindPropertyRelative("Name");
        sex = property.FindPropertyRelative("Sex");
        age = property.FindPropertyRelative("Age");
        description = property.FindPropertyRelative("Description");
        //绘制属性
        EditorGUI.PropertyField(top, personName, label);
        EditorGUI.PropertyField(middeLeft, sex);
        EditorGUI.PropertyField(middleRight, age);
        description.stringValue = EditorGUI.TextArea(bottom, description.stringValue);

        //Debug.Log(label.text);
        //Debug.Log(position);
        //while (property.NextVisible(true))
        //{
        //    Debug.Log($"OnGUI : {property.name}");
        //}

    }

    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        //while (property.NextVisible(true))
        //{
        //    Debug.Log($"GetPropertyHeight : {property.name}");
        //}
        return base.GetPropertyHeight(property, label);
    }


}
